<?php

namespace App\Common\Models;

use App\Common\Services\Common;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Question extends Model
{
    protected $table = 'common_question';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];
    public static function getList(Request $request)
    {
        $query = self::where('is_del', 1)->orderBy('create_at', 'desc');
        $isgetall = intval($request->isgetall) ?? 0;
        $question_title = $request->question_title ?? '';
        if ($question_title != '') {
            $query->where('question_title', 'like', '%' . $question_title . '%');
        }
        $is_send=$request->is_send ?? 0;
        if(in_array($is_send,[1,2])){
            $query->where('is_send',$is_send);
        }
        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return Common::paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
}